package com.briup.mr;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import javax.naming.Name;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author adam
 * @date 2023/5/31
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WordNum implements DBWritable, WritableComparable<WordNum> {
    private  String word;
    private  int  num;

    @Override
    public void write(PreparedStatement statement) throws SQLException {
        statement.setString(1, word);
        statement.setInt(2,num);


    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
         word = resultSet.getString("word");
         num=resultSet.getInt("num");

    }

    @Override
    public int compareTo(WordNum o) {
        return this.compareTo(o);
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(word);
        out.writeInt(num);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
       word= in.readUTF();
       num =in.readInt();
    }
}
